<?php

namespace app\admin\model;

use think\Model;


class Planrecords extends Model
{


    // 表名
    protected $name = 'planrecords';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'clickaverage',
        'clickrate'
    ];


    public function getClickAverageAttr($value, $data)
    {
        if ($data['click'] == 0) {
            return null;
        }
        return number_format($data['consume'] / $data['click'], 2, '.', '');
    }

    public function getClickRateAttr($value, $data)
    {
        if ($data['reveal'] == 0) {
            return null;
        }
        return (number_format($data['click'] / $data['reveal'] * 100, 2, '.', '')) . '%';
    }
}
